//
//  BottomOrigView.swift
//  Sinaweibo
//
//  Created by 谌桃 on 15/12/1.
//  Copyright © 2015年 ryan.chen. All rights reserved.
//

import UIKit
import SDWebImage
import SnapKit

class StatusOriginalView: UIView {
    
    var status:Status?{
    
        didSet{
        
            //绑定数据
            headImage.sd_setImageWithURL(status?.user?.headImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
            nameLabel.text = status?.user?.name
            mbrankImage.image = status?.user?.mbrankImage
            verified_type_image.image = status?.user?.verified_type_Image
            
            //TODO: 后期完善
            //            timeLabel.text = status?.created_at
            //            sourceLabel.text = status?.source
            contentLabel.text = status?.text
            
            //设置配图视图的图片数组 , 将模型图片url的属性赋值给 StatusPictureView类的属性 
            pictureView.imageURLs = status?.imageURLs
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
        
        super.init(coder: aDecoder)
    }
    
    //设置UI界面
    private func setupUI(){
        
    topView.backgroundColor = UIColor(white: 0.93, alpha: 1)
        
    //添加子控件
    addSubview(topView)
    addSubview(headImage)
    addSubview(nameLabel)
    addSubview(mbrankImage)
    addSubview(verified_type_image)
    addSubview(timeLabel)
    addSubview(sourceLabel)
    addSubview(contentLabel)
    addSubview(pictureView)
    
    //设置布局
    topView.snp_makeConstraints { (make) -> Void in
        make.left.top.right.equalTo(self)
        make.height.equalTo(8)
        
        }
        
        
    headImage.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(topView.snp_bottom).offset(8.0)
        make.left.equalTo(self).offset(StatusCellMargin)
        make.size.equalTo(CGSize(width: StatusCellImageWidth, height: StatusCellImageWidth))
    }
    
    nameLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        make.top.equalTo(headImage.snp_top)
        
    }
    
    mbrankImage.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        make.top.equalTo(nameLabel.snp_top)
    }
    
    verified_type_image.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(headImage.snp_right)
        make.centerY.equalTo(headImage.snp_bottom)
    }
    
    timeLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(headImage.snp_right).offset(StatusCellMargin)
        make.bottom.equalTo(headImage.snp_bottom)
    }
    
    sourceLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
        make.bottom.equalTo(timeLabel.snp_bottom)
    }
    
    contentLabel.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(self.snp_left).offset(StatusCellMargin)
        make.top.equalTo(headImage.snp_bottom).offset(StatusCellMargin)
    }
        
    
    pictureView.snp_makeConstraints { (make) -> Void in
        make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
        make.left.equalTo(contentLabel.snp_left)
        make.size.equalTo(CGSize(width: 180, height: 120))
    }
    
    self.snp_makeConstraints { (make) -> Void in
        make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin)
    }
}
    
    //懒加载所有的子视图
    
    private lazy var topView:UIImageView = UIImageView()
    
    private lazy var headImage: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    
    private lazy var nameLabel: UILabel = UILabel(title: "发布微博", color: UIColor.darkGrayColor(), fontSize: 14)
    
    private lazy var verified_type_image: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    private lazy var mbrankImage: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    private lazy var timeLabel: UILabel = UILabel(title: "12:12", color: UIColor.orangeColor(), fontSize: 10)
    
    private lazy var sourceLabel: UILabel = UILabel(title: "原来是小明", color: UIColor.darkGrayColor(), fontSize: 10)
    
    private lazy var contentLabel: UILabel = UILabel(title: "程序员工程师设计师", color: UIColor .darkGrayColor(), fontSize: 14,margin: StatusCellMargin)
    
    //配图视图
    private lazy var pictureView: StatusPictureView = StatusPictureView()

}

